package onlyTest;

import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.File;

/**
 * Created by zzy on 2017/12/30.
 */
public class PoiReadExcel {

    public static void main(String[] args) {
        //获取文件
        File file=new File("e:/poi_test.xls");

        try {
            //创建excel文件
            HSSFWorkbook workbook=new HSSFWorkbook(FileUtils.openInputStream(file));
            //获取工作表
            //HSSFSheet sheet=workbook.getSheet("Sheet0");
            HSSFSheet sheet=workbook.getSheetAt(0);
            int firstRowNum=0;
            int lastRowNum=sheet.getLastRowNum();

            for (int i=0;i<lastRowNum;i++){
                HSSFRow row=sheet.getRow(i);
                for (int j=0;j<row.getLastCellNum();j++){
                    HSSFCell cell=row.getCell(j);
                    System.out.print(cell.getStringCellValue()+" ");
                }
                System.out.println();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
